home *** CD-ROM | disk | FTP | other *** search
- /* 4567890123456789012345678901234567890123456789012345678901234567 */
- #include <Processes.h>
-
- #include "ProcessInfo.h"
-
- pascal OSErr InBackground(Boolean *inBackground) {
- ProcessSerialNumber theCurrentProcess;
- ProcessSerialNumber theFrontProcess;
- Boolean sameProcess;
- OSErr theError;
-
- theError = GetCurrentProcess(&theCurrentProcess);
- if (theError == noErr) {
- theError = GetFrontProcess(&theFrontProcess);
- }
- if (theError == noErr) {
- theError = SameProcess(&theCurrentProcess, &theFrontProcess,
- &sameProcess);
- if ((theError == noErr) && sameProcess) {
- *inBackground = false;
- } else {
- *inBackground = true;
- }
- }
- return theError;
- }
-
- pascal OSType GetSignature(void) {
- OSErr theError;
- OSType theSignature;
- ProcessInfoRec theInformation;
- ProcessSerialNumber theCurrentProcess;
-
- theInformation.processInfoLength = sizeof(ProcessInfoRec);
- theInformation.processName = nil; /* Don't care about name */
- theInformation.processAppSpec = nil; /* Don't care about spec */
-
- theError = GetCurrentProcess(&theCurrentProcess);
- if (theError == noErr) {
- theError =
- GetProcessInformation(&theCurrentProcess, &theInformation);
- }
- if (theError == noErr) {
- theSignature = theInformation.processSignature;
- } else {
- theSignature = '????';
- }
- return theSignature;
- }
-
- pascal OSErr GetProcessName(Str31 aName) {
- OSErr theError;
- ProcessInfoRec theInformation;
- ProcessSerialNumber theCurrentProcess;
-
- theInformation.processInfoLength = sizeof(ProcessInfoRec);
- theInformation.processName = aName;
- theInformation.processAppSpec = nil; /* Don't care about spec */
-
- theError = GetCurrentProcess(&theCurrentProcess);
- if (theError == noErr) {
- theError =
- GetProcessInformation(&theCurrentProcess, &theInformation);
- }
- return theError;
- }
-
- #define kSystemType 'FNDR'
- #define kFinderSig 'MACS'
-
- pascal OSErr FindFinder(ProcessSerialNumberPtr aPSN) {
- ProcessInfoRec theInformation;
- OSErr theError = noErr;
-
- aPSN->lowLongOfPSN = 0;
- aPSN->highLongOfPSN = kNoProcess;
- theInformation.processInfoLength = sizeof(ProcessInfoRec);
- theInformation.processName = nil; /* Don't care about name */
- theInformation.processAppSpec = nil; /* Don't care about spec */
- do {
- theError = GetNextProcess(aPSN);
- if (theError == noErr) {
- GetProcessInformation(aPSN, &theInformation);
- }
- } while(((theInformation.processSignature != kFinderSig) ||
- (theInformation.processType != kSystemType)) &&
- (theError == noErr));
- return(theError);
- }
-
- pascal OSErr BringFinderToFront(void) {
- OSErr theError;
- ProcessSerialNumber theFinder;
-
- theError = FindFinder(&theFinder);
- if (theError == noErr) {
- theError = SetFrontProcess(&theFinder);
- }
- return theError;
- }
-
-